﻿using Apps.Common;
using Apps.Models;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;

namespace ReportViewerForMvc
{
    /// <summary>
    /// The Web Form used for rendering a ReportViewer control.
    /// </summary>
    public partial class RlWeightReportWebForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //ReportViewer1.Drillthrough += new DrillthroughEventHandler(ReportViewer1_Drillthrough);
            BuildReportViewer();
        }

        private void BuildReportViewer()
        {
            if (!IsPostBack)
            {
                ReportViewerForMvc.ReportViewer.ID = ReportViewer1.ID;

                ReportViewer1.SetProperties(ReportViewerForMvc.ReportViewer);
            }
        }

        protected void ReportViewer1_Drillthrough(object sender, DrillthroughEventArgs e)
        {
            //LocalReport localReport = (LocalReport)e.Report;
            //IList<ReportParameter> list = localReport.OriginalParametersToDrillthrough;
            //var whereLambda = PredicateBuilder.True<V_STATS_RC_WEIGHTING>();
            //string RpSTIME = "", RpETIME = "", MATERIEL_ID = "", SUPPLIER_ID = "";
            //RpSTIME = list.Where(m=>m.Name== "RpSTIME").FirstOrDefault().Values[0].ToString();
            //RpETIME = list.Where(m=>m.Name== "RpETIME").FirstOrDefault().Values[0].ToString();
            //MATERIEL_ID = list.Where(m => m.Name == "MATERIEL_ID").FirstOrDefault().Values[0].ToString();
            //SUPPLIER_ID = list.Where(m => m.Name == "SUPPLIER_ID").FirstOrDefault().Values[0].ToString();
            //string IS_COAL = list.Where(m => m.Name == "IS_COAL").FirstOrDefault().Values[0].ToString();
            //List<V_STATS_RC_WEIGHTING> Data = new List<V_STATS_RC_WEIGHTING>();

            //if (IS_COAL == "1")
            //{
            //    whereLambda = whereLambda.And<V_STATS_RC_WEIGHTING>(m => m.IS_COAL == true);
            //}
            //else
            //{
            //    whereLambda = whereLambda.And<V_STATS_RC_WEIGHTING>(m => m.IS_COAL != true);
            //}

            //if (!string.IsNullOrWhiteSpace(MATERIEL_ID))
            //{
            //    whereLambda = whereLambda.And<V_STATS_RC_WEIGHTING>(m => m.MATERIEL_ID == MATERIEL_ID);
            //}

            //if (!string.IsNullOrWhiteSpace(SUPPLIER_ID))
            //{
            //    whereLambda = whereLambda.And<V_STATS_RC_WEIGHTING>(m => m.SUPPLIER_ID == SUPPLIER_ID);
            //}

            //if (!string.IsNullOrWhiteSpace(RpSTIME))
            //{
            //    DateTime FDATETime = Convert.ToDateTime(RpSTIME).Date;
            //    whereLambda = whereLambda.And<V_STATS_RC_WEIGHTING>(m => m.STATS_TIME >= FDATETime);
            //}
            //if (!string.IsNullOrWhiteSpace(RpETIME))
            //{
            //    DateTime FDATETime = Convert.ToDateTime(RpETIME).AddDays(1).Date;
            //    whereLambda = whereLambda.And<V_STATS_RC_WEIGHTING>(m => m.STATS_TIME <= FDATETime);
            //}

            //Data = Apps.BLL.Report.ReportBLL<V_STATS_RC_WEIGHTING>.GetReportDataList(whereLambda);

            //localReport.DataSources.Add(new ReportDataSource { Value = Data, Name = "DataSet_Detail" });

        }


        
    }
}